/**
 * Js控制主界面  完全实现交互数据下发至机器人端
 * @ HelloKun 2022.04
 */

//弹窗
import {getApp} from '../../common.js';
import prompt from '@system.prompt';

export default {

    data: {
        title: "你好,我是机器人小萌",
        work_status:"点击右侧按钮可以控制我哦",
        emoji:"表情聊天",
        talk_msg:"对萌萌说点什么",
        fontSize: '30px',
        Pink_Color: '#ffc0cb',
        White_color:'#ffffff',
        Black_color:'#000000',
        Yellow_Color: '#ffff00',
        Introduction:'我是小萌，\n我能说话、移动、控制家电等，\n更多功能等你探索，快和我玩吧！\nDesigned By @hellokun.cn\n ',
        front_img:'/common/images/mengmeng.png',
        fan:"/common/images/fanOff.png",
        door:"/common/images/doorLock.png",
        lamb:"/common/images/lambOff.png",
        water:"/common/images/waterOff.png",
        FanmodeFlag:"微微风",
        LambmodeFlag:"黄昏暗",

    },

    sendMessage(){
        var ret =1;
        var message = this.talk_msg;
        let commonInfo = {
            sessionId: getApp(this).ConfigParams.deviceInfo.sessionId
        };
        getApp(this).NetConfig.sendMessage(commonInfo, message, (result)=>{
                if(result.code==0)
                {
                    prompt.showToast({
                        message: "发送成功",
                        duration: 1000,
                    });
                ret =0;}
                else
                { prompt.showToast({
                        message: "发送失败",
                        duration: 1000,
                    });
               ret= -1;};
            });
        if(ret==0)
        {
            return 0;
        }
        else return -1;
    },


    PowerSwitchChange(e){
        console.log(e.checked);
        if( e.checked){
            this.About_me();
            this.talk_msg = "turn on MRobot";
            this.sendMessage();
            this.talk_msg = "3";
            this.sendMessage();
            console.log("open");
        }
        else{
            this.talk_msg = "reset MRobot";
            this.sendMessage();
            prompt.showToast({
                message: "断开"
            });
        };
    },
    //弹框
    showPrompt(msg) {
        prompt.showToast({
            message: msg,
            duration: 3000,
        });
    },
    ToGamePage(){
        this.work_status ="寓教于乐界面"
        console.log(this.$app.$def.data.game_page);
        //调用全局对象
        this.$app.$def.ToGamePage();
    },

    //运动控制
    Forward(){
        this.front_img='/common/images/up0.png';
        this.work_status ="萌萌退下";
        this.talk_msg = "F";
        this.sendMessage();
    },
    Backward(){
        this.front_img='/common/images/down0.png';
        this.work_status ="萌萌冲冲冲";
        this.talk_msg = "B";
        this.sendMessage();
    },
    TurnLeft(){
        this.front_img='/common/images/left0.png';
        this.work_status ="右转";
        this.talk_msg = "L";
        this.sendMessage();
    },
    TurnRight(){
        this.front_img='/common/images/right0.png';
        this.work_status ="左转";
        this.talk_msg = "R";
        this.sendMessage();
    },
    RunCircle(){
        this.front_img='/common/images/circle0.png';
        this.work_status ="转圈……";
        this.talk_msg = "C";
        this.sendMessage();
    },
    StopMove(){
        this.front_img='/common/images/left0.png';
        this.work_status ="休息中";
        this.talk_msg = "P";
        this.sendMessage();
    },

    //表情聊天
    Emoji_smile(){
        this.emoji ="微笑";
        this.talk_msg = "1";
       // this.sendMessage();
    },
    Emoji_wao(){
        this.emoji ="哇哦";
        this.talk_msg = "2";
        //this.sendMessage();
    },
    Emoji_haha(){
        this.emoji ="你好";
        this.talk_msg = "3";
        //this.sendMessage();
    },
    Emoji_wuwu(){
        this.emoji ="呜呜";
        this.talk_msg = "4";
       // this.sendMessage();
    },
    Emoji_light(){
        this.emoji ="光环";
        this.talk_msg = "5";
       // this.sendMessage();
    },
    Emoji_red(){
        this.emoji ="红灯停";
        this.talk_msg = "6";
       // this.sendMessage();
    },
    Emoji_yellow(){
        this.emoji ="黄灯等";
        this.talk_msg = "7";
       // this.sendMessage();
    },
    Emoji_green(){
        this.emoji ="绿灯行";
        this.talk_msg = "8";
       // this.sendMessage();
    },
    emoji_9()
    {
        this.emoji ="气温多少";
        this.talk_msg = "9";
    },
    emoji_msg_change(e)
    {
        this.emoji = e.value;
        this.talk_msg=e.value;
    },

    //秒控设备
    Control_fan(e)
    {
        console.log(e.checked);
        if( e.checked){
            this.showFanPanel();
            this.talk_msg = "turn on fan lev2";
            this.sendMessage();
            this.fan="/common/images/fanOn.png";
            this.emoji_9();
            this.sendMessage();
            prompt.showToast({
                message: "打开风扇"
            });
        }
        else{
            this.fan ="/common/images/fanOff.png";
            this.talk_msg = "turn off fan";
            this.sendMessage();
            prompt.showToast({
                message: "关闭风扇"
            });
        };
    },
    Control_door(e)
    {
        if( e.checked){
            this.door="/common/images/doorOpen.png";
            this.talk_msg = "open door";
            this.sendMessage();
            console.log("open");
            prompt.showToast({
                message: "打开门锁"
            });
        }
        else{
            this.door="/common/images/doorLock.png";
            this.talk_msg = "close door";
            this.sendMessage();
            prompt.showToast({
                message: "关闭门锁"
            });
        };
    },
    Control_lamb(e)
    {
        if( e.checked){
            this.talk_msg = "turn on lamb lev2";
            this.sendMessage();
            this.lamb="/common/images/lambOn.png";
            this.showLambPanel();
            console.log("open");
            prompt.showToast({
                message: "打开台灯"
            });
        }
        else{
            this.talk_msg = "turn off lamb";
            this.sendMessage();
            this.lamb="/common/images/lambOff.png";
            prompt.showToast({
                message: "关闭台灯"
            });
        };
    },
    Control_water(e)
    {
        if( e.checked){
            this.talk_msg = "go ahead water";
            this.sendMessage();
            this.water="/common/images/waterOn.png";
            console.log("open");
            prompt.showToast({
                message: "浇水中"
            });
        }
        else{
            this.water="/common/images/waterOff.png";
            this.talk_msg = "stop water";
            this.sendMessage();
            prompt.showToast({
                message: "停止浇水"
            });
        };
    },

    //点击Designed By HelloKun 弹出Dialog  并接收机器人返回数据
    About_me(){
        let commonInfo = {
            sessionId: getApp(this).ConfigParams.deviceInfo.sessionId
        };
        getApp(this).NetConfig.registerMsgReceive(commonInfo,(result)=>{
            if(result.code==0)
            {
              prompt.showToast({
                  message:"收到："+result.data,
                  duration:1000,
              });
            }
        });
        this.$element('dialog_about_me').show();
    },
    confirmClick(e) {
        this.$element('dialog_about_me').close()
        prompt.showToast({
            message: '感谢使用'
        })
    },
    About_control(){
        this.$element('dialog_control').show();
    },

    dialog_control_ok()
    {
        this.$element('dialog_control').close()
    },
    //去云端控制界面
    web_mqtt()
    {
        this.$app.$def.ToWebMqtt();
    },
    showFanPanel() {
        this.$element('FanPanel').show()
    },
    closeFanPanel() {
        this.$element('FanPanel').close()
    },
    changeMode(e) {
        this.modeFlag = e.mode
    },
    showLambPanel() {
        this.$element('LambPanel').show()
    },
    closeLambPanel() {
        this.$element('LambPanel').close()
    },
    FanLev1()
    {
        this.talk_msg = "turn on fan lev1";
        this.fan='/common/images/fan_leve1.png';
        this.FanmodeFlag = "微微风";
        this.sendMessage();
        prompt.showToast({
            message: "风扇一档"
        });
    },
    FanLev2()
    {
        this.talk_msg = "turn on fan lev2";
        this.fan='/common/images/fan_leve2.png';
        this.FanmodeFlag = "轻柔风";
        this.sendMessage();
        prompt.showToast({
            message: "风扇二档"
        });
    },
    FanLev3()
    {
        this.talk_msg = "turn on fan lev3";
        this.fan='/common/images/fan_leve3.png';
        this.FanmodeFlag = "大狂风";
        this.sendMessage();
        prompt.showToast({
            message: "风扇三档"
        });
    },
   LambLev1()
    {
        this.talk_msg = "turn on lamb lev1";
        this.lamb='/common/images/lamb_leve1.png';
        this.LambmodeFlag = "黄昏暗";
        this.sendMessage();
        prompt.showToast({
            message: "台灯一档-黄昏暗"
        });

    },
    LambLev2()
    {
        this.talk_msg = "turn on lamb lev2";
        this.lamb='/common/images/lamb_leve2.png';
        this.LambmodeFlag = "晨曦明";
        this.sendMessage();
        prompt.showToast({
            message: "台灯三档-晨曦明"
        });
    },
    LambLev3()
    {
        this.talk_msg = "turn on lamb lev3";
        this.lamb='/common/images/lamb_leve3.png';
        this.LambmodeFlag = "正午亮";
        this.sendMessage();
        prompt.showToast({
            message: "台灯三档-正午亮"
        });
    },


}


